<template>
    <div class="gooeyMenu">
        <div :class="(isMaster && portalSelectList.length > 1)?'menu-block-2':'menu-block-1'">
            <el-popover
                v-if="isMaster && portalSelectList.length > 1&&canChange"
                placement="left"
                width="140"
                trigger="click">
                <div class="command-list">
                    <template v-for="item in portalSelectList">
                        <!-- <el-button @click="changeCurInstance(item.ID)" :class="curInstance.ID == item.ID ? 'active' : ''" v-show="item.Type!=0">{{ item.Name }}</el-button> -->
                        <div class="block" @click="changeCurInstance(item.ID)" :class="curInstance.ID == item.ID ? 'active' : ''" v-show="item.Type!=0">
                            <span class="left"><i v-html="item.Type==2?IconMap.myplan:IconMap.defaultplan"></i></span>
                            <span class="right">{{ item.Name }}</span>
                        </div>
                    </template>
                </div>

                <div class="menu-item" slot="reference" @click="editDivVisible=false;$parent.layoutChanged=false;$parent.isLock=true">
                    <span :title="Terms.portal.toggle" v-html="IconMap.toggle" style="width: 18px;height: 18px;"></span>
                </div>
            </el-popover>
            <p @click="changeCurInstance(false)" class="proxyChangeType" :title="Terms.portal.toggle" v-html="IconMap.toggle"  v-else-if="isMaster && portalSelectList.length > 1&&!canChange">

            </p>
            <el-popover
                placement="left"
                width="140"
                v-model="editDivVisible"
                trigger="manual">
                <div class="command-list" >
                    <div class="block" @click="handleAddComponent">
                        <span class="left"><span v-html="IconMap.newadd"></span></span>
                        <span class="right">{{ Terms.portal.add }}</span>
                    </div>
                    <div class="block" @click="handleBackupComponent">
                        <span class="left"><span v-html="IconMap.backup"></span></span>
                        <span class="right">{{ Terms.portal.backup }}</span>
                    </div>
                    
                    <!-- <div class="block" @click="handleSetLock">
                        <span class="left">
                            <span v-if="!isLock" v-html="IconMap.newunlock"></span>
                            <span v-html="IconMap.newlock" v-else></span>
                        </span>
                        <span class="right">{{ isLock ?  Terms.portal.edit : Terms.portal.saveEdit }}</span>                        
                    </div> -->
                    <div class="block" @click="deletePersonPortal" v-if="showResetDefault">
                        <span class="left"><span v-html="IconMap.newdelete"></span></span>
                        <span class="right">{{ Terms.portal.reset }}</span>
                    </div>
                    <div class="block" @click="deleteCurrentPortal" v-if="isMaster && portalSelectList.length>=2" >
                        <span class="left"><span v-html="IconMap.newdelete"></span></span>
                        <span class="right">{{ Terms.portal.delete }}</span>
                    </div>
                    <!-- <div class="block" @click="editDivVisible=false">
                        <span class="left"><span v-html="IconMap.newclose"></span></span>
                        <span class="right">{{ Terms.portal.close }}</span>
                    </div> -->
                </div>

                <div class="menu-item" slot="reference" @click="handleSetLock">
                    <span :title="editDivVisible?Terms.portal.close:Terms.portal.edit" :class="editDivVisible?'icon-portal icon-t-check active':'icon-portal icon-t-pencil'" ></span>
                </div>
            </el-popover>

        </div>
    </div>
</template>
<script>
import Icon from './Icon.vue'
import IconMap from './IconMap'
import { Terms } from "./lib/Term";

export default {
    name: 'GooetMenu',
    props: ["isLock", "curInstance", "portalSelectList","isMaster"],
    components: { Icon },
    data() {

        const isSafari = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)
        return {
            IconMap:IconMap,
            isSafari,
            Terms:Terms,
            editDivVisible:false
        }
    },
    computed:{
        showResetDefault(){
            let result = this.portalSelectList.filter(item=>item.Type==2)
            if(!this.isMaster && result.length > 0){
                return true
            }
            return false
        },
        portalId(){
            return this.curInstance.ID
        },
        canChange(){
            return JSON.stringify(this.$parent.lastLayoutData) == JSON.stringify(this.$parent.layoutData)
        }
    },
    watch:{
        isLock:function(val){
            if(val&&this.editDivVisible){
                this.editDivVisible=!val
            }
        }
    },
    methods: {
        
        changeCurInstance(id) {
            if(!id){
                Funcs.Notify(Terms.message.warn,Terms.portal.notify,'warning')
                return
            }
           
            
            this.$emit('curInstanceSelectChange', id)
        },
        handleBackupComponent(){
            this.$emit('backup')
        },
        handleAddComponent() {
            this.$emit('addComponent')
        },
        handleShowGlobalConfig() {
            this.$emit('showGlobalConfig')
        },
        handleSetLock() {
            this.editDivVisible=!this.editDivVisible
            let val = !this.isLock
            this.isLock = val
            this.$emit('lockChange', val)
        },
        handleShowAuxiliaryConfig() {
            this.$emit('showAuxiliaryConfig')
        },
        deletePersonPortal() {
            this.$emit('deletePersonPortal')
        },
        deleteCurrentPortal(){
            this.$emit('deleteCurrentPortal')
        }

    }
}

</script>
<style scoped>

.icon-portal {
    width: 18px;
    height: 18px;
    font-size: 18px;
}
.icon-portal.active{

    color:var(--color)
}
.command-list{
    background: #ffffff;border-radius: 2px;
}
.command-list .block {
    height: 36px;line-height: 36px;padding-left: 8px;
}

.command-list .block .left {
    display: inline;line-height: 20px;vertical-align: middle;
}
.command-list .block .right {
    margin-left: 8px;
    display: inline-block;
}

.command-list .block:hover,
.command-list .block.active {
    background-color: #F0F2F5;
    color: var(--color);
    cursor: pointer;
    pointer-events: auto;
}
.gooeyMenu {
    position: fixed;
    right: 3vw;
    bottom: 5vh;
    z-index: 100;
}
.gooeyMenu .menu-block-2 {
    width: 42px;
    height: 100px;
    background: #ffffff;
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    color: #454845;
    box-shadow: 0px 3px 6px 0px rgb(0 0 0 / 15%);
}
.gooeyMenu .menu-block-2:hover {
    color:var(--color);
}

.gooeyMenu .menu-block-1 {
    width: 42px;
    background: #ffffff;
    border-radius: 45px;
    display: flex;
    justify-content: center;
    color: var(--color);    
}
/* .gooeyMenu .menu-block:hover{
    cursor: pointer;
    pointer-events: auto;
    color: var(--color-hover);
} */

.gooeyMenu .menu-block .menu-item {
    width: 100%;
    height: 32px;
    background: white;
    border-radius: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
<style lang="scss" scoped>
.proxyChangeType {
   color: #454845;
   margin: 10px 0;
   margin-left: 11px;
   width: 18px;
   height: 18px;
   cursor: pointer;

}
.proxyChangeType:hover {
   color: var(--color);
}
.is-disabled,
.is-disabled:focus,
.is-disabled:hover {
    color: #c0c4cc !important;
    cursor: not-allowed !important;
    background-image: none !important;
    background-color: #fff !important;
    border-color: #ebeef5 !important;
}

.el-button.active {
    color: var(--color);
    border-color: var(--color);
    outline: 0;
}

$menu-items: 4;

%goo {
    filter: url('#shadowed-goo');
}

%ball {
    background: white;
    border-radius: 100%;
    width: 40px;
    height: 40px;
    // position: absolute;
    top: 4px;
    right: 0;
    color: #454845;//var(--color);
    transform: translate3d(0, 0, 0);
    transition: transform ease-out 0.2s, background-color ease-out 0.2s,
        color ease-out 0.2s;
    // box-shadow: 0 0 2px var(--color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-open {
    display: none;
}

.menu-item {
    @extend %ball;

    &:focus {
        outline: none;
    }
}

.hamburger {
    width: 14px;
    height: 2px;
    background: var(--color);
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -1px;
    transition: transform 200ms;
}

$hamburger-spacing: 6px;

.hamburger-1 {
    transform: translate3d(0, -$hamburger-spacing, 0);
}

.hamburger-2 {
    transform: translate3d(0, 0, 0);
}

.hamburger-3 {
    transform: translate3d(0, $hamburger-spacing, 0);
}

.menu-open:checked+.menu-open-button {
    .hamburger-1 {
        transform: translate3d(0, 0, 0) rotate(45deg);
    }

    .hamburger-2 {
        transform: translate3d(0, 0, 0) scale(0.1, 1);
    }

    .hamburger-3 {
        transform: translate3d(0, 0, 0) rotate(-45deg);
    }
}

.menu {
    @extend %goo;
    // $width:300px;
    $height: 48px;
    position: fixed;
    right: 3vw;
    bottom: 5vh;
    // width:$width;
    height: $height;
    box-sizing: border-box;
    font-size: 20px;
    text-align: right;
    z-index: 999;
}

.menu-item {
    &:hover {
        background: var(--color), 80;
        color: var(--color);
        cursor: pointer;
    }

    @for $i from 1 through $menu-items {
        &:nth-child(#{$i + 2}) {
            transition-duration: 180ms;
        }
    }
}

.menu-open-button {
    @extend %ball;
    z-index: 2;
    transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition-duration: 400ms;
    transform: scale(1.1, 1.1) translate3d(0, 0, 0);
    cursor: pointer;
}

.menu-open-button:hover {
    transform: scale(1.2, 1.2) translate3d(0, 0, 0);
}

.menu-open:checked+.menu-open-button {
    transition-timing-function: linear;
    transition-duration: 200ms;
    transform: scale(0.8, 0.8) translate3d(0, 0, 0);
}

.menu-open:checked~.menu-item {
    transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);

    @for $i from 1 through $menu-items {
        &:nth-child(#{$i + 2}) {
            transition-duration: 90ms+ (100ms * $i);
            transform: translate3d(-60px * $i, 0, 0);
        }
    }
}

#filterSvg {
    display: none;
}
</style>
